<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<title>E1 - Solution | pansis.io</title>
<link rel="shortcut icon" href="https://github.pansis.site/favicon.ico">
<link href="https://github.pansis.site/styles/main.css" rel="stylesheet">
<link href="//at.alicdn.com/t/c/font_1678829_b85ccgkdqkr.css" rel="stylesheet">
<link href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css" rel="stylesheet">
<link rel="alternate" type="application/rss+xml" title="pansis.io » Feed" href="https://github.pansis.site/atom.xml">
        <meta name="description" content="E1 - Solution
A 带鱼除法



难度
考点




1
换行符，基本运算



题目分析
xxx 个带鱼，每天吃 yyy 个，按照整除的知识可知能吃 x/y 个，按照余数的知识可以吃 x%y 个，同时注意输出换行符 \n 。..." />
        <meta name="keywords" content="比赛" />
        <!-- OG -->
        <meta property="og:locale" content="zh_CN">
        <meta property="og:title" content="E1 - Solution" />
        <meta property="og:type" content="article" />
        <meta property="og:description" content="E1 - Solution
A 带鱼除法



难度
考点




1
换行符，基本运算



题目分析
xxx 个带鱼，每天吃 yyy 个，按照整除的知识可知能吃 x/y 个，按照余数的知识可以吃 x%y 个，同时注意输出换行符 \n 。...">
        <meta property="og:url" content="https://github.pansis.site/post/e1-solution/" />
        <meta property="og:site_name" content="pansis.io">
        <meta property="og:updated_time" content="2023-09-19">
        <meta property="og:image" content="" />
        <meta property="og:image:secure_url" content="">
        <meta property="og:image:alt" content="E1 - Solution">
        <!-- Twitter (post.ejs) -->
        <meta name="twitter:card" content="summary_large_image">
        <meta name="twitter:title" content="E1 - Solution">
        <meta name="twitter:description" content="E1 - Solution
A 带鱼除法



难度
考点




1
换行符，基本运算



题目分析
xxx 个带鱼，每天吃 yyy 个，按照整除的知识可知能吃 x/y 个，按照余数的知识可以吃 x%y 个，同时注意输出换行符 \n 。...">
        <!-- <meta name="twitter:site" content="@WBoy0609">
        <meta name="twitter:creator" content="@WBoy0609"> -->
        <meta name="twitter:image" content="">
</head>

<body>
    <div class="main animated">
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <a href="https://github.pansis.site">pansis.io</a>
        </div>
    </div>
    <div class="my_socials">
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
        <a href="https://github.pansis.site/atom.xml" title="rss" target="_blank"><i class="iconfont icon-rss"></i></a>
    </div>
</div>

    <div class="header_menu">
        
            
                <a href="/" class="menu">首页</a>
            
        
            
                <a href="/tag/GWAaV2nvk/" class="menu">程序设计课程</a>
            
        
            
                <a href="/tag/24hangc" class="menu">比赛</a>
            
        
            
                <a href="/tag/L7r9STb75/" class="menu">Python教程</a>
            
        
            
                <a href="/tags" class="menu">分类</a>
            
        
        <div class="gridea-search-div">
            <form id="gridea-search-form" action="https://github.pansis.site/search/">
                <input class="gridea-search-input" autocomplete="off" spellcheck="false" name="q"/>
            </form>
        </div>
    </div>

            <div class="autopagerize_page_element">
                <div class="content">
                    <div class="post_page">
                        <div class="post animated fadeInDown">
                            <div class="post_title post_detail_title">
                                <h2>
                                    E1 - Solution
                                </h2>
                                <span class="article-info">
                                    2023-09-19, 3836 words, 18 min read
                                </span>
                            </div>
                            <div class="post_content markdown">
                                <p class="md_block">
                                    <span class="md_line md_line_start md_line_end">
                                        <h1 id="e1-solution">E1 - Solution</h1>
<h2 id="a-带鱼除法"><code>A</code> 带鱼除法</h2>
<table>
<thead>
<tr>
<th>难度</th>
<th>考点</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>换行符，基本运算</td>
</tr>
</tbody>
</table>
<h3 id="题目分析">题目分析</h3>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>x</mi></mrow><annotation encoding="application/x-tex">x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathdefault">x</span></span></span></span> 个带鱼，每天吃 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>y</mi></mrow><annotation encoding="application/x-tex">y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span></span></span></span> 个，按照整除的知识可知能吃 <code>x/y</code> 个，按照余数的知识可以吃 <code>x%y</code> 个，同时注意输出换行符 <code>\n</code> 。</p>
<p>本题不要用循环去模拟吃鱼的过程，多从数学方向去思考，而不是随便写循环去模拟。</p>
<h3 id="示例代码">示例代码</h3>
<pre><code class="language-c">#include &lt;stdio.h&gt;
int main()
{
	int x, y;
	scanf(&quot;%d%d&quot;, &amp;x, &amp;y);
	printf(&quot;%d\n&quot;, x / y);
	printf(&quot;%d&quot;, x % y);
    return 0;
}
</code></pre>
<h2 id="b-简单的能量块"><strong><code>B</code></strong> 简单的能量块</h2>
<table>
<thead>
<tr>
<th style="text-align:center">难度</th>
<th style="text-align:center">考点</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">1</td>
<td style="text-align:center">判断</td>
</tr>
</tbody>
</table>
<h3 id="题目分析-2">题目分析</h3>
<p>这是一道简单的能量块问题</p>
<p>可能需要注意的要点有：</p>
<ol>
<li>输入输出，还有格式问题</li>
<li>变量初始化为 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span></span></span></span> （如答案中记录 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mo>∑</mo><mo>+</mo></msub></mrow><annotation encoding="application/x-tex">\sum_+</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.108041em;vertical-align:-0.35804100000000005em;"></span><span class="mop"><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.10862099999999997em;"><span style="top:-2.40029em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">+</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.35804100000000005em;"><span></span></span></span></span></span></span></span></span></span> 的 <code>s1</code> 和记录 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mo>∑</mo><mo>−</mo></msub></mrow><annotation encoding="application/x-tex">\sum_-</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.108041em;vertical-align:-0.35804100000000005em;"></span><span class="mop"><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.10862099999999997em;"><span style="top:-2.40029em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">−</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.35804100000000005em;"><span></span></span></span></span></span></span></span></span></span> 的 <code>s2</code> ）</li>
<li>判断条件的书写</li>
<li>变量名只能由英文字母、数字、下划线组成，且第一个字符不能为数字，所以一定不要用希腊字母去命名变量哦~</li>
</ol>
<h3 id="示例代码-2">示例代码</h3>
<pre><code class="language-c">#include &lt;stdio.h&gt;
int main()
{
    int a;
    int s1 = 0,s2 = 0; //s1记录正数，s2记录负数
    for(int i = 1; i &lt;= 4; ++i) //循环读入四个数
    {
        scanf(&quot;%d&quot;, &amp;a);
        if(a &gt; 0) s1 += a; //判断
        else s2 += a;
    }
    printf(&quot;%d\n%d&quot;, s1, s2); //输出
    return 0;
}
</code></pre>
<h2 id="c-摩卡与小学期"><code>C</code> 摩卡与小学期</h2>
<table>
<thead>
<tr>
<th>难度</th>
<th>考点</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>分支结构</td>
</tr>
</tbody>
</table>
<h3 id="题目分析-3">题目分析</h3>
<p>根据题目要求，我们先要对预先给定个数的 <code>贡献值</code> 求和，然后根据题目描述和样例，进行一个判断：如果 <code>贡献值</code> 之和小于等于 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span></span></span></span>， 则 Moca 团队一个需求也没有完成；如果 <code>贡献值</code> 之和大于等于 <code>老师发布的需求数</code>，那么 Moca 团队完成了老师发布的全部需求；否则 Moca 团队完成了与贡献值之和相等的需求。</p>
<p>此题需要注意的就是一些特殊的数据点，这里故意设了几个数据点，包括 Moca 团队的贡献值之和<strong>恰好等于</strong> <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span></span></span></span> ，Moca 团队的贡献值之和<strong>恰好等于</strong>老师发布的需求数，这两种情况下按照题意是要输出特殊语句的。有的同学忽略了临界情况，即在分支结构的条件判断中没有写等号，导致没能通过特殊数据点。</p>
<p>其次还有一点需要额外说明的是，一些同学用变量 <code>sum</code> 保存贡献值之和，在 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>m</mi><mi>a</mi><mi>i</mi><mi>n</mi></mrow><annotation encoding="application/x-tex">main</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.65952em;vertical-align:0em;"></span><span class="mord mathdefault">m</span><span class="mord mathdefault">a</span><span class="mord mathdefault">i</span><span class="mord mathdefault">n</span></span></span></span> 里定义了 <code>sum</code> 但是没有初始化，这种情况下会导致 <code>sum</code> 的初值不一定是 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span></span></span></span>，原因在此不过多赘述。总之，大家一定要注意类似于这样的问题，即应该写 <code>int sum = 0;</code> 。</p>
<h3 id="示例代码-3">示例代码</h3>
<pre><code class="language-c">#include &lt;stdio.h&gt;

int main()
{
    int sum = 0;
    int n, a, need;
    scanf(&quot;%d&quot;, &amp;n);
    for(int i = 1; i &lt;= n; i++)
    {
        scanf(&quot;%d&quot;, &amp;a);
        sum = sum + a;
    }
    scanf(&quot;%d&quot;, &amp;need);
    
    if( sum &lt;= 0 ) {
    	printf(&quot;%d\n&quot;, 0);		// 根据题意，贡献值为负或者为 0 时是一个需求也没完成的情况
        printf(&quot;Moca finish 0 requirement!&quot;);
    }
    else if( sum &gt;= need ) {
    	printf(&quot;%d\n&quot;, need);	// 根据题意，贡献值大于等于老师发布的需求则完成了所有需求
        printf(&quot;Moca finish all requirements!&quot;);
    }
    else {
    	printf(&quot;%d\n&quot;, sum);
    }
    
    return 0;
}
</code></pre>
<h2 id="d-czx-的出游计划"><code>D</code> czx 的出游计划</h2>
<table>
<thead>
<tr>
<th>难度</th>
<th>考点</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>条件语句</td>
</tr>
</tbody>
</table>
<h3 id="题目分析-4">题目分析</h3>
<p>根据题目意思，先读入相应的数据，随后用 <code>if-else</code> 语句判断一下 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>o</mi><mi>p</mi></mrow><annotation encoding="application/x-tex">op</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">o</span><span class="mord mathdefault">p</span></span></span></span> 是哪一种情况，开两个变量记录小牛的兴奋值和愉悦值（记得初始化），根据题意依次计算即可。</p>
<h3 id="示例代码-4">示例代码</h3>
<pre><code class="language-c">#include &lt;stdio.h&gt;

int main() {
    int a1, a2, a3, b1, b2, b3, op;
    int x = 0, res = 0; //兴奋值和愉悦值
    scanf(&quot;%d%d%d%d%d%d%d&quot;, &amp;a1, &amp;b1, &amp;a2, &amp;b2, &amp;a3, &amp;b3, &amp;op);
    if (op == 1) {
        x += a1, res += x * b1;
        x += a2, res += x * b2;
        x += a3, res += x * b3;
    } else if (op == 2) {
        x += a2, res += x * b2;
        x += a3, res += x * b3;
        x += a1, res += x * b1;
    } else if (op == 3) {
        x += a3, res += x * b3;
        x += a2, res += x * b2;
        x += a1, res += x * b1;
    }
    printf(&quot;%lld\n&quot;, res);
    return 0;
}
</code></pre>
<h2 id="e-阶乘对对碰"><code>E</code> 阶乘对对碰</h2>
<table>
<thead>
<tr>
<th style="text-align:left">难度</th>
<th>考点</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">2</td>
<td>循环 判断语句</td>
</tr>
</tbody>
</table>
<h3 id="题目分析-5">题目分析</h3>
<p>题目考察的是关于简单的循环语句和判断语句的使用。</p>
<p>首先，根据阶乘与双阶乘的公式，利用 for 循环求得最后 $ a $ 的阶乘和 $ b $ 的双阶乘。</p>
<p>然后，比较 $ a $ 的阶乘和 $ b $ 的双阶乘的大小并对其大小关系进行输出。</p>
<p>特别地，需要注意 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn><mo>!</mo><mo>=</mo><mn>0</mn><mo>!</mo><mo>!</mo><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">0!=0!!=1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord">0</span><span class="mclose">!</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord">0</span><span class="mclose">!</span><span class="mclose">!</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span></span></span></span> 。</p>
<h3 id="示例代码-5">示例代码</h3>
<pre><code class="language-c">#include &lt;stdio.h&gt;

int main()
{
	// 输入两个小于10的数
	int a, b;
	scanf(&quot;%d %d&quot;, &amp;a, &amp;b);

	// 计算a的阶乘和b的双阶乘
	int a_factorial = 1;

	for (int i = 1; i &lt;= a; i++)
	{
		a_factorial *= i;
	}

	int b_double_factorial = 1;

	for (int i = b; i &gt; 0; i -= 2)
	{
		b_double_factorial *= i;
	}

	printf(&quot;%d %d\n&quot;, a_factorial, b_double_factorial);

	// 比较两者的大小，并输出
	if (a_factorial &gt; b_double_factorial)
	{
		printf(&quot;a!&gt;b!!&quot;);
	}
	else if(a_factorial &lt; b_double_factorial)
	{
		printf(&quot;a!&lt;b!!&quot;);
	}
	else printf(&quot;a!=b!!&quot;);
	return 0;
}
</code></pre>
<h2 id="f-入学考试"><code>F</code> 入学考试</h2>
<table>
<thead>
<tr>
<th>难度</th>
<th>考点</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>判断</td>
</tr>
</tbody>
</table>
<h3 id="问题分析">问题分析</h3>
<p>题意较好理解。我们需要读入所有学生的成绩，并把及格学生的成绩挑选出来单独计算。对每个学生的成绩进行判断是否及格，如果及格，则计入及格学生的总分中；同时，需要记录所有学生的总分。在判断的过程中记录及格人数和总人数，最后计算得到答案。</p>
<p>注意所有计数变量都需初始化。</p>
<h3 id="参考代码">参考代码</h3>
<pre><code class="language-C">#include &lt;stdio.h&gt;

int main()
{
	int a, score, sum = 0, sumj = 0, cnt = 0, cntj = 0;
	scanf(&quot;%d%d&quot;, &amp;a, &amp;score);
	while (score != -1)
	{
		if (score &gt;= a)
		{
			sumj += score;
			cntj++;
		}
		sum += score;
		cnt++;
		scanf(&quot;%d&quot;, &amp;score);
	}
	printf(&quot;%d %d &quot;, cntj, sum / cnt);
	if (cntj)
		printf(&quot;%d&quot;, sumj / cntj);
	else
		printf(&quot;-1&quot;);
	return 0;
}
</code></pre>
<h2 id="g-czx-与优购超市"><code>G</code> czx 与优购超市</h2>
<table>
<thead>
<tr>
<th>难度</th>
<th>考点</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>条件语句</td>
</tr>
</tbody>
</table>
<h3 id="题目分析-6">题目分析</h3>
<p>每次操作，可以使用四个 <code>if-else</code> 语句确定 czx 的举动，然后先判断该次举动能否成功执行（钱够不够？商店里有没有剩余？czx 是否还拥有？）并输出相应的语句，如果成功了，还需要进行相应的更改（扣除一定的钱和商店里的剩余数量，扣除 czx 拥有的水果数量）。</p>
<p>在判断操作能否执行的时候，注意判断符号应当用 <code>&lt;</code> 还是 <code>&lt;=</code> 。</p>
<p>在 std 里，两个商品的价格被设为了常量，这可以避免在打代码时手误打错，并使代码的可读性提高。同时也要注意自己使用的变量名尽量有意义，在使用变量较多时，一昧的定义 <code>a,b,c,d,e,...</code> 等意义不明显的变量，容易导致代码难以调试，出现“自己写的代码自己都看不懂”的情况。</p>
<h3 id="示例代码-6">示例代码</h3>
<pre><code class="language-c">#include &lt;stdio.h&gt;

int main()
{
	const int priceA = 3, priceB = 2;
	int n, x, a, b, ownA = 0, ownB = 0;
	scanf(&quot;%d%d%d%d&quot;, &amp;n, &amp;x, &amp;a, &amp;b);
	for (int i = 1; i &lt;= n; i++)
	{
		int u, v;
		scanf(&quot;%d%d&quot;, &amp;u, &amp;v);
		if (u == 0)       // try to buy
		{
			if (v == 0)   // apple
			{
				if (x &gt;= priceA &amp;&amp; a &gt; 0)
				{
					a--;
                    x -= priceA;
                    ownA++;
					puts(&quot;Ok!&quot;);
				}
				else
					puts(&quot;Failed!&quot;);
			}
			else          // banana
			{
				if (x &gt;= priceB &amp;&amp; b &gt; 0)
				{
					b--;
                    x -= priceB;
                    ownB++;
					puts(&quot;Ok!&quot;);
				}
				else
					puts(&quot;Failed!&quot;);
			}
		}
		else              // try to eat
		{
			if (v == 0)   // apple
			{
				if (ownA &gt; 0)
				{
					ownA--;
					puts(&quot;Ok!&quot;);
				}
				else
					puts(&quot;Failed!&quot;);
			}
			else          // banana
			{
				if (ownB &gt; 0)
				{
					ownB--;
					puts(&quot;Ok!&quot;);
				}
				else
					puts(&quot;Failed!&quot;);
			}
		}
	}
	printf(&quot;%d %d %d&quot;, a, b, x);
	return 0;
}
</code></pre>
<h2 id="h-ne小杨掷骰子吗"><code>H</code> Ne：小杨掷骰子吗</h2>
<table>
<thead>
<tr>
<th>难度</th>
<th>考点</th>
</tr>
</thead>
<tbody>
<tr>
<td>4</td>
<td>循环、枚举</td>
</tr>
</tbody>
</table>
<h3 id="题目分析-7">题目分析</h3>
<p>​	题目要求判断是否存在一种情况，使得三个骰子的红色面之和为 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>A</mi></mrow><annotation encoding="application/x-tex">A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathdefault">A</span></span></span></span> ，且黑色面之和恰好为 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>B</mi></mrow><annotation encoding="application/x-tex">B</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span></span></span></span> ，我们考虑直接三重循环枚举所有情况，第一重为枚举第一个骰子的面朝向，第二和第三同理。</p>
<p>​	另外，我们假设两个数 <code>sum_A</code> 记录红色朝上的和， <code>sum_B</code>  记录黑色朝上的和。如果当前朝上的面是1或者4，那么我们就给 <code>sum_A</code> 加上这个数，如果不是，则给 <code>sum_B</code> 加上这个数。</p>
<p>​	那么，如果 <code>sum_A == A &amp;&amp; sum_B == B</code> 则说明可以组成题目要求的结果，输出 <code>Yes</code> ，如果循环全部结束了还是没有判定成功的情况，则输出 <code>No</code></p>
<h3 id="示例代码-7">示例代码</h3>
<pre><code class="language-c">#include &lt;stdio.h&gt;

int main()
{
	int test;
	int a, b;
	scanf(&quot;%d&quot;, &amp;test);
	while(test--)
	{
		scanf(&quot;%d %d&quot;, &amp;a, &amp;b);
		int jud = 0;
		for(int i = 1; i &lt;= 6; i++)
			for(int j = 1; j &lt;= 6; j++)
				for(int k = 1; k &lt;= 6; k++)
				{
					int A = 0, B = 0;
					if(i == 1 || i == 4) A += i;
					else B += i;
					if(j == 1 || j == 4) A += j;
					else B += j;
					if(k == 1 || k == 4) A += k;
					else B += k;
					if(A == a &amp;&amp; B == b)
						jud = 1;
				}
		if(jud) printf(&quot;Yes\n&quot;);
		else printf(&quot;No\n&quot;);
	}
	return 0;
}
</code></pre>
<h2 id="i-将军点兵"><code>I</code> 将军点兵</h2>
<table>
<thead>
<tr>
<th>难度</th>
<th>考点</th>
</tr>
</thead>
<tbody>
<tr>
<td>2(枚举法) or 4(中国剩余定理)</td>
<td>循环，判断，取模运算</td>
</tr>
</tbody>
</table>
<h3 id="题目分析-8">题目分析</h3>
<p>重述题目：本题给定三个除数 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>x</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">x_i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> 和对应的余数 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>y</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">y_i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>，求满足条件的被除数 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi></mrow><annotation encoding="application/x-tex">result</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mord mathdefault">e</span><span class="mord mathdefault">s</span><span class="mord mathdefault">u</span><span class="mord mathdefault" style="margin-right:0.01968em;">l</span><span class="mord mathdefault">t</span></span></span></span> 。</p>
<p>事实上，最笨的办法便是<strong>从1开始</strong>使用，使用循环找到满足条件的被除数，这个方法是最慢的（循环次数最多），但很显然本题作者允许你这样写了。使用这一思路的同学可以参看示例代码1。</p>
<p>那么有没有什么简化的办法呢？显然我们可以只去找那些被 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>x</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">x_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> 除余 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>y</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">y_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> 的数，再判断是否满足 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>x</mi><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">x_2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> 与 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>x</mi><mn>3</mn></msub></mrow><annotation encoding="application/x-tex">x_3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> 的条件。这样我们从循环变量的角度减少循环次数。使用这一思路的同学可以参看示例代码2。</p>
<p>还有没有其他方法？我们可以使用如下公式来构造我们的被除数：</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mo>=</mo><msub><mi>n</mi><mn>1</mn></msub><mo>∗</mo><mo>(</mo><msub><mi>x</mi><mn>2</mn></msub><mo>∗</mo><msub><mi>x</mi><mn>3</mn></msub><mo>)</mo><mo>+</mo><msub><mi>n</mi><mn>2</mn></msub><mo>∗</mo><mo>(</mo><msub><mi>x</mi><mn>1</mn></msub><mo>∗</mo><msub><mi>x</mi><mn>3</mn></msub><mo>)</mo><mo>+</mo><msub><mi>n</mi><mn>3</mn></msub><mo>∗</mo><mo>(</mo><msub><mi>x</mi><mn>1</mn></msub><mo>∗</mo><msub><mi>x</mi><mn>2</mn></msub><mo>)</mo></mrow><annotation encoding="application/x-tex">result = n_1 * (x_2 * x_3) + n_2 * (x_1 * x_3) + n_3 * (x_1 * x_2)
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mord mathdefault">e</span><span class="mord mathdefault">s</span><span class="mord mathdefault">u</span><span class="mord mathdefault" style="margin-right:0.01968em;">l</span><span class="mord mathdefault">t</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.61528em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">n</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.61528em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">n</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.61528em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">n</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span></span></p>
<p>可以认为我们的被除数由被加号 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>+</mo></mrow><annotation encoding="application/x-tex">+</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.66666em;vertical-align:-0.08333em;"></span><span class="mord">+</span></span></span></span> 三部分构成，三部分中，只有第一部分 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>n</mi><mn>1</mn></msub><mo>∗</mo><mo>(</mo><msub><mi>x</mi><mn>2</mn></msub><mo>∗</mo><msub><mi>x</mi><mn>3</mn></msub><mo>)</mo></mrow><annotation encoding="application/x-tex">n_1 * (x_2 * x_3)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.61528em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">n</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span> 不能被 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>x</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">x_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> 整除，于是我们要让这一部分满足被 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>x</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">x_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> 除余 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>y</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">y_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> 即可，类似地构造其余部分，需要注意我们应当对结果取模（<span class="katex"><span class="katex-mathml"><math><semantics><mrow><msub><mi>x</mi><mn>1</mn></msub><mo>∗</mo><msub><mi>x</mi><mn>2</mn></msub><mo>∗</mo><msub><mi>x</mi><mn>3</mn></msub></mrow><annotation encoding="application/x-tex">x_1 * x_2 * x_3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.61528em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.61528em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>）。这样我们进一步简化循环，使用这一思路的同学你很棒，可以参看示例代码3。</p>
<h2 id="qa">Q&amp;A</h2>
<p>Q：为什么能简化循环，这样做有什么意义？</p>
<p>A：从示例代码1到3，我们能够发现循环过程中的循环变量更新的步长变大了，这也意味着我们预先排除的数变多了，从而可以简化循环，简化循环有助于减少运算次数，节约时间成本，另一个原因是后续的比赛中大家会经常见到”TLE“。</p>
<h3 id="示例代码1">示例代码1</h3>
<pre><code class="language-c">#include&lt;stdio.h&gt;
int main()
{
	//读取
	int m1, m2, m3; //除数
	int res1, res2, res3; //余数
	scanf(&quot;%d%d%d%d%d%d&quot;, &amp;m1, &amp;res1, &amp;m2, &amp;res2, &amp;m3, &amp;res3);
	//处理
	int mul = 1; //结果
	int flag = 0; //标志
	for(; flag != 1; mul++)
	{
		if(mul % m1 == res1)
		{
			if(mul % m2 == res2)
			{
				if(mul % m3 == res3)
				{
					flag = 1;
				}
			}
		}
	}
	printf(&quot;%d&quot;, mul - 1); //由于使用for循环，跳出前会多自增一次，需要减去
	return 0;
}
</code></pre>
<h3 id="示例代码2">示例代码2</h3>
<pre><code class="language-c">#include&lt;stdio.h&gt;
int main()
{
	//读取
	int m1, m2, m3;
	int res1, res2, res3;
	scanf(&quot;%d%d%d%d%d%d&quot;, &amp;m1, &amp;res1, &amp;m2, &amp;res2, &amp;m3, &amp;res3);
	//处理
	int mul = res1;
	for(int flag = 0; flag != 1; mul += m1)
	{
		if(mul % m2 == res2)
		{
			if(mul % m3 == res3)
			{
				flag = 1;
			}
		}
	}
	printf(&quot;%d&quot;, mul - m1);
	return 0;
}
</code></pre>
<h3 id="示例代码3">示例代码3</h3>
<pre><code class="language-c">#include&lt;stdio.h&gt;
int main()
{
	//读取
	int m1, m2, m3;
	int res1, res2, res3;
	scanf(&quot;%d%d%d%d%d%d&quot;, &amp;m1, &amp;res1, &amp;m2, &amp;res2, &amp;m3, &amp;res3);
	//处理
	int mul = m1 * m2 * m3;
	int result = 0;
	int t1 = mul / m1, t2 = mul / m2, t3 = mul / m3;
	int tmp = t1 % m1; //当前循环变量
	int cnt = 1;
	while(tmp != 1) //先找到余1的
	{
		cnt++;
		tmp = (t1 % m1) * (cnt % m1) % m1;
	}
	result += (res1 * cnt % mul) * t1 % mul; //再利用乘法找到余res1的
	//使用取余运算防止乘法溢出
	//当然使用long long int 也可以。
	//以下类似
	tmp = t2 % m2;
	cnt = 1;
	while(tmp != 1)
	{
		cnt++;
		tmp = (t2 % m2) * (cnt % m2) % m2;
	}
	result = result % mul + (res2 * cnt % mul) * t2 % mul;
	tmp = t3 % m3;
	cnt = 1;
	while(tmp != 1)
	{
		cnt++;
		tmp = (t3 % m3) * (cnt % m3) % m3;
	}
	result = result % mul + (res3 * cnt % mul) * t3 % mul;
	//需要注意，此处得到的结果并不一定是最小的，需要取模得到最小的。
	printf(&quot;%d&quot;, result % mul);
	return 0;
}
</code></pre>
<h2 id="j-基于快速数论变换的加密算法"><code>J</code> 基于快速数论变换的加密算法</h2>
<table>
<thead>
<tr>
<th style="text-align:left">难度</th>
<th style="text-align:left">考点</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">3(枚举) or 5(解密算法)</td>
<td style="text-align:left">循环，模运算</td>
</tr>
</tbody>
</table>
<p>一方面，我们希望同学们观察加密算法的加密过程，熟悉模运算中简单的加法逆元与简单的乘法逆元，我们有：</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mtable><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>x</mi><mo>−</mo><mn>1</mn><mi>y</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>≡</mo><mi>x</mi><mo>+</mo><mn>4</mn><mi>y</mi><mspace></mspace><mspace width="1em"/><mo>(</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi></mrow><mspace width="0.3333333333333333em"/><mn>5</mn><mo>)</mo></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>x</mi><mo>−</mo><mn>2</mn><mi>y</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>≡</mo><mi>x</mi><mo>+</mo><mn>3</mn><mi>y</mi><mspace></mspace><mspace width="1em"/><mo>(</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi></mrow><mspace width="0.3333333333333333em"/><mn>5</mn><mo>)</mo></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>x</mi><mo>−</mo><mn>3</mn><mi>y</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>≡</mo><mi>x</mi><mo>+</mo><mn>2</mn><mi>y</mi><mspace></mspace><mspace width="1em"/><mo>(</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi></mrow><mspace width="0.3333333333333333em"/><mn>5</mn><mo>)</mo></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>x</mi><mo>−</mo><mn>4</mn><mi>y</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>≡</mo><mi>x</mi><mo>+</mo><mn>1</mn><mi>y</mi><mspace></mspace><mspace width="1em"/><mo>(</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi></mrow><mspace width="0.3333333333333333em"/><mn>5</mn><mo>)</mo></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mfrac><mn>1</mn><mn>2</mn></mfrac><mi>x</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>≡</mo><mn>3</mn><mi>x</mi><mspace></mspace><mspace width="1em"/><mo>(</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi></mrow><mspace width="0.3333333333333333em"/><mn>5</mn><mo>)</mo></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mfrac><mn>1</mn><mn>3</mn></mfrac><mi>x</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>≡</mo><mn>2</mn><mi>x</mi><mspace></mspace><mspace width="1em"/><mo>(</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi></mrow><mspace width="0.3333333333333333em"/><mn>5</mn><mo>)</mo></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mfrac><mn>1</mn><mn>4</mn></mfrac><mi>x</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>≡</mo><mn>4</mn><mi>x</mi><mspace></mspace><mspace width="1em"/><mo>(</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi></mrow><mspace width="0.3333333333333333em"/><mn>5</mn><mo>)</mo></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">\begin{aligned}
    x - 1 y &amp; \equiv x + 4 y \pmod{5} \\
    x - 2 y &amp; \equiv x + 3 y \pmod{5} \\
    x - 3 y &amp; \equiv x + 2 y \pmod{5} \\
    x - 4 y &amp; \equiv x + 1 y \pmod{5} \\
    \frac{1}{2} x &amp; \equiv 3 x \pmod{5} \\
    \frac{1}{3} x &amp; \equiv 2 x \pmod{5} \\
    \frac{1}{4} x &amp; \equiv 4 x \pmod{5} \\
\end{aligned}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:12.922320000000003em;vertical-align:-6.2111600000000005em;"></span><span class="mord"><span class="mtable"><span class="col-align-r"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:6.711160000000001em;"><span style="top:-9.192600000000002em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">1</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span></span></span><span style="top:-7.692600000000001em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">2</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span></span></span><span style="top:-6.1926000000000005em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">3</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span></span></span><span style="top:-4.6926000000000005em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">4</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span></span></span><span style="top:-2.71116em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">2</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mord mathdefault">x</span></span></span><span style="top:-0.40371999999999886em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">3</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mord mathdefault">x</span></span></span><span style="top:1.9037200000000003em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">4</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mord mathdefault">x</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:6.2111600000000005em;"><span></span></span></span></span></span><span class="col-align-l"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:6.711160000000001em;"><span style="top:-9.192600000000002em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≡</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">4</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace allowbreak"></span><span class="mspace" style="margin-right:1em;"></span><span class="mopen">(</span><span class="mord"><span class="mord"><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span></span></span><span class="mspace" style="margin-right:0.3333333333333333em;"></span><span class="mord">5</span><span class="mclose">)</span></span></span><span style="top:-7.692600000000001em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≡</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">3</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace allowbreak"></span><span class="mspace" style="margin-right:1em;"></span><span class="mopen">(</span><span class="mord"><span class="mord"><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span></span></span><span class="mspace" style="margin-right:0.3333333333333333em;"></span><span class="mord">5</span><span class="mclose">)</span></span></span><span style="top:-6.1926000000000005em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≡</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">2</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace allowbreak"></span><span class="mspace" style="margin-right:1em;"></span><span class="mopen">(</span><span class="mord"><span class="mord"><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span></span></span><span class="mspace" style="margin-right:0.3333333333333333em;"></span><span class="mord">5</span><span class="mclose">)</span></span></span><span style="top:-4.6926000000000005em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≡</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">1</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace allowbreak"></span><span class="mspace" style="margin-right:1em;"></span><span class="mopen">(</span><span class="mord"><span class="mord"><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span></span></span><span class="mspace" style="margin-right:0.3333333333333333em;"></span><span class="mord">5</span><span class="mclose">)</span></span></span><span style="top:-2.71116em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≡</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord">3</span><span class="mord mathdefault">x</span><span class="mspace allowbreak"></span><span class="mspace" style="margin-right:1em;"></span><span class="mopen">(</span><span class="mord"><span class="mord"><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span></span></span><span class="mspace" style="margin-right:0.3333333333333333em;"></span><span class="mord">5</span><span class="mclose">)</span></span></span><span style="top:-0.40371999999999886em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≡</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord">2</span><span class="mord mathdefault">x</span><span class="mspace allowbreak"></span><span class="mspace" style="margin-right:1em;"></span><span class="mopen">(</span><span class="mord"><span class="mord"><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span></span></span><span class="mspace" style="margin-right:0.3333333333333333em;"></span><span class="mord">5</span><span class="mclose">)</span></span></span><span style="top:1.9037200000000003em;"><span class="pstrut" style="height:3.32144em;"></span><span class="mord"><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≡</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord">4</span><span class="mord mathdefault">x</span><span class="mspace allowbreak"></span><span class="mspace" style="margin-right:1em;"></span><span class="mopen">(</span><span class="mord"><span class="mord"><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span></span></span><span class="mspace" style="margin-right:0.3333333333333333em;"></span><span class="mord">5</span><span class="mclose">)</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:6.2111600000000005em;"><span></span></span></span></span></span></span></span></span></span></span></span></p>
<p>注意，在 C 语言中，如果 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>x</mi><mo>&lt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">x \lt 0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">&lt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span></span></span></span> 且 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>y</mi><mo>&gt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">y \gt 0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.7335400000000001em;vertical-align:-0.19444em;"></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span></span></span></span>，那么 <code>x % y</code> 的值一定不是正数。</p>
<p>在加密算法中，<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>e</mi><mo separator="true">,</mo><mi>g</mi></mrow><annotation encoding="application/x-tex">e, g</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">e</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault" style="margin-right:0.03588em;">g</span></span></span></span> 由 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>a</mi><mo separator="true">,</mo><mi>c</mi></mrow><annotation encoding="application/x-tex">a, c</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">a</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault">c</span></span></span></span> 决定，<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>f</mi><mo separator="true">,</mo><mi>h</mi></mrow><annotation encoding="application/x-tex">f, h</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault">h</span></span></span></span> 由 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>b</mi><mo separator="true">,</mo><mi>d</mi></mrow><annotation encoding="application/x-tex">b, d</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">b</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault">d</span></span></span></span> 决定，<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>i</mi><mo separator="true">,</mo><mi>j</mi></mrow><annotation encoding="application/x-tex">i, j</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.85396em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">i</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault" style="margin-right:0.05724em;">j</span></span></span></span> 由 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>e</mi><mo separator="true">,</mo><mi>f</mi></mrow><annotation encoding="application/x-tex">e, f</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">e</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span></span></span></span>，<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>k</mi><mo separator="true">,</mo><mi>l</mi></mrow><annotation encoding="application/x-tex">k, l</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathdefault" style="margin-right:0.03148em;">k</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault" style="margin-right:0.01968em;">l</span></span></span></span> 由 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>g</mi><mo separator="true">,</mo><mi>h</mi></mrow><annotation encoding="application/x-tex">g, h</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathdefault" style="margin-right:0.03588em;">g</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault">h</span></span></span></span> 决定，所以我们可以根据二元一次方程组的求解得到以下代码：</p>
<pre><code class="language-c">#include &lt;stdio.h&gt;
int main(void) {
    int i, j, k, l;
    scanf(&quot;%d%d%d%d&quot;, &amp;i, &amp;j, &amp;k, &amp;l);
    int g = (k + 1 * l) * 3 % 5;
    int h = (k + 4 * l) * 4 % 5;
    int e = (i + 1 * j) * 3 % 5;
    int f = (i + 4 * j) * 3 % 5;
    int a = (e + 1 * g) * 3 % 5;
    int b = (f + 1 * h) * 3 % 5;
    int c = (e + 4 * g) * 3 % 5;
    int d = (f + 4 * h) * 3 % 5;
    printf(&quot;%d %d %d %d&quot;, a, b, c, d);
    return 0;
}
</code></pre>
<p>另一方面，我们希望同学们不观察加密算法的加密过程，熟悉 <code>for</code> 循环与 <code>if</code> 选择。</p>
<p>由于加密前 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>a</mi><mo separator="true">,</mo><mi>b</mi><mo separator="true">,</mo><mi>c</mi><mo separator="true">,</mo><mi>d</mi></mrow><annotation encoding="application/x-tex">a, b, c, d</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">a</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault">b</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault">c</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault">d</span></span></span></span> 都是小于 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>5</mn></mrow><annotation encoding="application/x-tex">5</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">5</span></span></span></span> 的自然数，我们可以使用 <code>for</code> 循环枚举全部可能的 <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>，直接使用题目给出的加密算法进行加密，然后使用 <code>if</code> 选择符合条件的情况。这样我们就得到了如下代码：</p>
<pre><code class="language-c">#include &lt;stdio.h&gt;
int main() {
    int m, n, o, p;
    scanf(&quot;%d%d%d%d&quot;, &amp;m, &amp;n, &amp;o, &amp;p);
    int a, b, c, d;
    for (a = 0; a &lt; 5; a++) {
        for (b = 0; b &lt; 5; b++) {
            for (c = 0; c &lt; 5; c++) {
                for (d = 0; d &lt; 5; d++) {
                    int e = (a + 1 * c) % 5;
                    int f = (b + 1 * d) % 5;
                    int g = (a + 4 * c) % 5;
                    int h = (b + 4 * d) % 5;
                    int i = (e + 1 * f) % 5;
                    int j = (e + 4 * f) % 5;
                    int k = (g + 2 * h) % 5;
                    int l = (g + 3 * h) % 5;
                    if (i == m &amp;&amp; j == n &amp;&amp; k == o &amp;&amp; l == p) {
                        printf(&quot;%d %d %d %d&quot;, a, b, c, d);
                    }
                }
            }
        }
    }
    return 0;
}
</code></pre>
<p>我们建议学有余力的同学阅读题目中的思考部分。</p>
<h1 id="-end-">- End -</h1>
<br />
                                            
                                </p>
                            </div>
                            <div class="post_footer">
                                
                                    <div class="meta">
                                        <div class="info"><span class="field tags"><i class="iconfont icon-tag-sm"></i>
                                                
                                                    <a href="https://github.pansis.site/tag/0kvGbp_AE/" class="article-info">
                                                        比赛
                                                    </a>
                                                    
                                            </span>
                                        </div>
                                    </div>
                                    
                                        
                            </div>
                        </div>
                        
                            
                                <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<div id="gitalk-container" style="padding-bottom: 20px;"></div>
<script>
    var pageId = (location.pathname).substring(1, 49) // Ensure uniqueness and length less than 50
    pageId = pageId.endsWith('/') ? pageId.slice(0, -1) : pageId // 以斜杠结尾则去除
    var gitalk = new Gitalk({
        clientID: '9d5eba33618472c44a07',
        clientSecret: '065a85ed04333ceebfc4f01d7ca1674175730339',
        repo: 'fzxl2003.github.io',
        owner: 'fzxl2003',
        admin: ['fzxl2003'],
        id: pageId,
        distractionFreeMode: false  // Facebook-like distraction free mode
    })
    gitalk.render('gitalk-container')
</script>
                                    
                                        
                                                    
                    </div>
                </div>
            </div>
    </div>
    <div class="footer">
    
    <div class="powered_by">
        <a href="https://codeberg.org/kytrun/gridea-theme-one" target="_blank">Theme One,</a>
        <a href="https://open.gridea.dev/" target="_blank">Powered by Gridea&#65281;</a>
    </div>
    
    
        <div class="footer_slogan">
            Powered by <a href="https://github.com/getgridea/gridea" target="_blank">Gridea</a>
        </div>
    
    <div id="back_to_top" class="back_to_top">
        <span>△</span>
    </div>
    
</div>

<script src="https://github.pansis.site/media/scripts/util.js"></script>
        <link rel="stylesheet" href="//unpkg.com/@highlightjs/cdn-assets@11.5.1/styles/default.min.css">
        <script src="//unpkg.com/@highlightjs/cdn-assets@11.5.1/highlight.min.js"></script>
        <script>hljs.highlightAll();</script>
</body>

</html>